//
//  LKAllTrendsViewController.m
//  Mideleague_Agent
//
//  Created by Zhiwang on 2020/6/12.
//  Copyright © 2020 Zhiwang. All rights reserved.
//

#import "LKAllTrendsViewController.h"
#import "LKMyAllTrendCell.h"
#import "LKMyAlltrensModel.h"
@interface LKAllTrendsViewController ()<UITableViewDelegate,UITableViewDataSource>

@property(nonatomic,strong)LKBaseTableview *tableView;
@property(nonatomic,strong)NSMutableArray *dataArray;


@end

@implementation LKAllTrendsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"全部动态";
    [self createTableview];
    [self getAllTrendListData];
    // Do any additional setup after loading the view.
}
-(void)createTableview{
    self.tableView = [LKBaseTableview setTableviewWithFrame:CGRectZero style:UITableViewStyleGrouped registercellClasss:@[@"LKMyAllTrendCell"]];
    [self.tableView registerNib:[UINib nibWithNibName:@"LKMyAllTrendCell" bundle:nil] forCellReuseIdentifier:@"LKMyAllTrendCell"];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _tableView.emptyDataSetSource = self;
    _tableView.emptyDataSetDelegate = self;
    _tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
    _tableView.backgroundColor = viewDefualtColor;
    [self.view addSubview:_tableView];
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.view);
        make.top.equalTo(self.view).offset(NAVIGATION_BAR_HEIGHT );
        make.bottom.equalTo(self.view).offset(0);
    }];

    if (@available(iOS 11.0, *)) {
        self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    } else {
        // Fallback on earlier versions
    }
    self.tableView.estimatedRowHeight = 500;
//    [self.tableView reloadData];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return self.dataArray.count;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    LKMyAllTrendCell *cell = [tableView dequeueReusableCellWithIdentifier:@"LKMyAllTrendCell"];
    cell.model = self.dataArray[indexPath.section];
    return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return UITableViewAutomaticDimension;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *header = [[UIView alloc] init];
    return header;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 1.0f;
}
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    UIView *footerView = [[UIView alloc] init];
    return footerView;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0.0000000001f;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
}
/// 获取我的所有动态的数据列表
-(void)getAllTrendListData{
    [SVProgressHUD show];
    NSDictionary *param = @{@"token":[LKUserInforTool account].token,@"id":self.mid};
    [[LKNetDataManager defaultManager] sendRequestMethod:HTTPMethodPOST serverUrl:ServerlUrl apiPath:MyAllTrendsListUrl header:[LKUserInforTool account].token parameters:param progress:^(NSProgress * _Nullable progress) {
        
    } success:^(BOOL isSuccess, id  _Nullable responseObject) {
        [SVProgressHUD dismiss];
        if ([responseObject[@"code"] isEqualToString:@"success"]) {
            NSArray *dataAray = responseObject[@"data"];
            for (NSDictionary *dic in dataAray) {
                LKMyAlltrensModel *model = [LKMyAlltrensModel modelWithDictionary:dic];
                [self.dataArray addObject:model];
            }
            [self.tableView reloadData];
        }else{
            
        }

    } failure:^(NSString * _Nullable errorMessage) {
        
    }];
}
-(NSMutableArray *)dataArray{
    if (_dataArray == nil) {
        _dataArray = [[NSMutableArray alloc] init];
    }
    return _dataArray;
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
